package com.l.dbtransfer.utils;
/**  
* @author 严秋旺
* @date 2017-11-17 16:17:42
*/

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import com.l.dbtransfer.JdbcInfo;

public class DbUtils {

    public static Connection createConnection(String type) throws ClassNotFoundException, SQLException {
        JdbcInfo jdbcInfo = getJdbcInfo(type);
        Class.forName(jdbcInfo.getDriver());
        return DriverManager.getConnection(jdbcInfo.getUrl(), jdbcInfo.getUsername(), jdbcInfo.getPassword());
    }

    public static JdbcInfo getJdbcInfo(String type) {
        JdbcInfo jdbcInfo = new JdbcInfo();
        jdbcInfo.setDriver(ConfigUtils.getProperty(type + ".jdbc.driver"));
        jdbcInfo.setUrl(ConfigUtils.getProperty(type + ".jdbc.url"));
        jdbcInfo.setUsername(ConfigUtils.getProperty(type + ".jdbc.username"));
        jdbcInfo.setPassword(ConfigUtils.getProperty(type + ".jdbc.password"));
        return jdbcInfo;
    }

}
